package com.twu.exercise;

import java.util.ArrayList;

public class PrimeFactors {
    public String generate(int number) {
        StringBuilder result=new StringBuilder();
        ArrayList<String> factors = new ArrayList<String>();

        for (int i = 2; i < number + 1; i++) {
            if (number % i == 0) {
                factors.add(Integer.toString(i));
                number = number / i;
            }
        }

        for (int i = 0; i < factors.size(); i++) {
            result.append(factors.get(i));
            if (i!=factors.size()-1) result.append(",");
        }

        return result.toString();
    }
}
